# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
from __future__ import unicode_literals

import scrapy
import datetime
from mongoengine import Document
from mongoengine.fields import *

class NovelData(Document):
    """
    @summary:小说概览信息
    """
    platform = StringField(default=u'创客小说', verbose_name='平台')
    title = StringField(required=False, verbose_name='标题')
    desc = StringField(default='', verbose_name='描述')
    author = StringField(default='', verbose_name='作者')
    category = StringField(default='', verbose_name='分类')
    links = StringField(default='', verbose_name='链接')
    cover = StringField(verbose_name='封面图片存储路径')
    cover_link = StringField(default='', verbose_name='封面图片链接')
    popularity = StringField(default='', verbose_name='人气')
    finished = BooleanField(default=False, verbose_name='是否抓取完成')
    crawl_chapter_max = IntField(default=0, verbose_name='抓取最大章节数')
    add_time = DateTimeField(
        db_field='createtime',
        default=datetime.datetime.now,
        verbose_name='创建时间',
    )

    def __unicode__(self):
        return '%s %s %s %s' % \
               (self.title,
                self.author,
                self.category,
                self.desc
                )

    meta = {
        'db_alias': "novelSpider",
        'strict': False,
        'index_background': True,
        "collection": "NovelData",
        "indexes": [
            "title",
            "author",
            'category',
        ]
    }


class ChapterData(Document):
    """
    @summary:小说章节信息
    """
    platform = StringField(default=u'创客小说', verbose_name='平台')
    title = StringField(required=True, verbose_name='标题')
    chapter = StringField(required=True, verbose_name='章节')
    chapter_num = IntField(required=True, verbose_name='章节编号')
    chapter_text = StringField(required=True, default='', verbose_name='章节内容')
    add_time = DateTimeField(
        db_field='createtime',
        default=datetime.datetime.now,
        verbose_name='创建时间',
    )

    meta = {
        'db_alias': "novelSpider",
        'strict': False,
        'index_background': True,
        "collection": "ChapterData",
        "indexes": [
            "title",
            "chapter",
            'chapter_num',
        ]
    }

    def __unicode__(self):

        return '%s %s' % (self.title, self.chapter)